
#include "Char.h"

#include <math.h>

// DEBUG.
#include "Debug.h"

using namespace Riccsson::System;

REGISTER_CLASS_CPP(Char)
{

}

//---------------------------------------------------------------------------------------
int Char::CompareTo(Char* value)
{
	return _internalChar > (*value)._internalChar ? 1 : _internalChar < (*value)._internalChar ? -1 : 0;
}
//---------------------------------------------------------------------------------------
int Char::CompareTo(object* value)
{
	if (!(instanceof(value, Char)))
		return false;

	return ((Char*)value)->_internalChar == _internalChar;
}
//---------------------------------------------------------------------------------------
bool Char::Equals(Char* obj)
{
	return _internalChar == (*obj)._internalChar;
}
//---------------------------------------------------------------------------------------
bool Char::Equals(object* obj)
{
	if (!(instanceof(obj, Char)))
		return false;

	return ((Char*)obj)->_internalChar == _internalChar;
}
//---------------------------------------------------------------------------------------
int Char::GetHashCode()
{
	return _internalChar;
}
//---------------------------------------------------------------------------------------
TypeCode Char::GetTypeCode()
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Char::Parse(string* s)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Char::Parse(string* s, IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Char::Parse(string* s, Globalization::NumberStyles style)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
int Char::Parse(string* s, Globalization::NumberStyles style, IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Char::ToString()
{
	bool isNegative(false);
	if(_internalChar < 0)
	{
		isNegative = true;
		_internalChar = -_internalChar;
	}

	int length = (int) log10((double) _internalChar);
	char* intToString = new char[length + 2];

	int x = _internalChar;
	int i = (int) log10((double) x);
	while(x > 0)
	{
		intToString[i] = (x % 10) + '0';
		x = x / 10;
		i = i - 1;
	}

	intToString[length + 1] = '\0';

	if(isNegative)
	{
		char* intToString2 = new char[length + 2 + 1];
		for(int i = 1; (intToString2[i] = intToString[i-1]) != '\0'; i++);
		intToString2[0] = '-';
		delete intToString;
		intToString = intToString2;
	}

	GC_PTR<string> output( new string(intToString) );

	delete intToString;
	intToString = null;

	return output;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Char::ToString(IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Char::ToString(string* format)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Char::ToString(const char* format)
{
	throw;
}
//---------------------------------------------------------------------------------------
GC_PTR<Riccsson::System::string> Char::ToString(string* format, IFormatProvider* provider)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
bool Char::TryParse(string* s, char out result)
{
	throw;
}
//---------------------------------------------------------------------------------------
// Static.
bool Char::TryParse(string* s, Globalization::NumberStyles style, IFormatProvider* provider, char out result)
{
	throw;
}




//----------------------------------------------------------------------------
// +
Char Char::operator+ ( const Char value )
{
	return Char(this->_internalChar + value._internalChar);
}

//----------------------------------------------------------------------------
// -
Char Char::operator- ( const Char value )
{
	return Char(this->_internalChar - value._internalChar);
}

//----------------------------------------------------------------------------
// *
Char Char::operator* ( const Char value )
{
	return Char(this->_internalChar * value._internalChar);
}

//----------------------------------------------------------------------------
// /
Char Char::operator/ ( const Char value )
{
	return Char(this->_internalChar / value._internalChar);
}
Char Char::operator/ ( const char& value )
{
	return Char(this->_internalChar / value);
}

//----------------------------------------------------------------------------
// %
Char Char::operator% ( const Char value )
{
	return Char(this->_internalChar % value._internalChar);
}